package com.chen.controller;

import com.chen.common.BaseContext;
import com.chen.entity.R;
import com.chen.entity.ShoppingCart;
import com.chen.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
@Slf4j
public class ShoppingCartConteroller {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/list")
    public R list() {
        Long userId = BaseContext.getCurrentId();
        List<ShoppingCart> list = shoppingCartService.shoppingCartList(userId);
        return R.success(list);
    }

    @PostMapping("/add")
    public R add(@RequestBody ShoppingCart shoppingCart) {
        ShoppingCart shoppingCart1 = shoppingCartService.addSC(shoppingCart);
        return R.success(shoppingCart1);
    }
    @DeleteMapping("/clean")
    public R clean(){
        shoppingCartService.clean();
        return  R.success("清除成功");
    }



    @PostMapping("/sub")
    public R sub(@RequestBody ShoppingCart shoppingCart){
        shoppingCartService.sub(shoppingCart);
        return  R.success("删除成功");
    }
}
